﻿using System;
using System.Data;
using System.Collections.Generic;
using Slja.Model;
using System.Text.RegularExpressions;
namespace Slja.BLL
{
    /// <summary>
    /// ShopBLL
    /// </summary>
    public partial class ShopBLL
    {
        private readonly Slja.DAL.ShopDAL dal = new Slja.DAL.ShopDAL();
        public ShopBLL()
        { }

        public string GetShopFromKeyWord(string keyword, string CityID)
        {
            string strXml = "";
            if (keyword.Length >= 2 || keyword.Length == 0)
            {
                Regex regChz2 = new Regex(@"[\u0391-\uFFE5]{2,}");//2个以上的汉字
               // Regex regEng2 = new Regex(@"[A-Z,a-z]{2,}");//2个以上的拼音字母

                string strWhere = "[City]=" + CityID;
                if (regChz2.IsMatch(keyword))
                {
                    strWhere += " and ShopName like '%" + keyword + "%'";
                }
                //if (regEng2.IsMatch(keyword))
                //{
                //    strWhere = " Pinyin like '" + keyword + "%' OR ShortPy like '" + keyword + "%'";
                //}

                //ClientDAL dal = new RegionCity();
                DataSet ds = dal.GetList(strWhere);
                if (ds.Tables.Count > 0)
                {
                    strXml = BLLCommon.BuildXmlData(ds.Tables[0], "ShopID", "ShopName", "{0}*{1}", "{1}");
                }
            }
            return strXml;
        }
        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Slja.Model.ShopModel model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Slja.Model.ShopModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ShopID)
        {

            return dal.Delete(ShopID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string ShopIDlist)
        {
            return dal.DeleteList(ShopIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Slja.Model.ShopModel GetModel(int ShopID)
        {

            return dal.GetModel(ShopID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Slja.Model.ShopModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Slja.Model.ShopModel> DataTableToList(DataTable dt)
        {
            List<Slja.Model.ShopModel> modelList = new List<Slja.Model.ShopModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Slja.Model.ShopModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Slja.Model.ShopModel();
                    if (dt.Rows[n]["ShopID"] != null && dt.Rows[n]["ShopID"].ToString() != "")
                    {
                        model.ShopID = int.Parse(dt.Rows[n]["ShopID"].ToString());
                    }
                    if (dt.Rows[n]["ShopName"] != null && dt.Rows[n]["ShopName"].ToString() != "")
                    {
                        model.ShopName = dt.Rows[n]["ShopName"].ToString();
                    }
                    if (dt.Rows[n]["City"] != null && dt.Rows[n]["City"].ToString() != "")
                    {
                        model.City = int.Parse(dt.Rows[n]["City"].ToString());
                    }
                    if (dt.Rows[n]["Address"] != null && dt.Rows[n]["Address"].ToString() != "")
                    {
                        model.Address = dt.Rows[n]["Address"].ToString();
                    }
                    if (dt.Rows[n]["TLCode"] != null && dt.Rows[n]["TLCode"].ToString() != "")
                    {
                        model.TLCode = dt.Rows[n]["TLCode"].ToString();
                    }
                    if (dt.Rows[n]["InnerCode"] != null && dt.Rows[n]["InnerCode"].ToString() != "")
                    {
                        model.InnerCode = dt.Rows[n]["InnerCode"].ToString();
                    }
                    if (dt.Rows[n]["ShopLev"] != null && dt.Rows[n]["ShopLev"].ToString() != "")
                    {
                        model.ShopLev = dt.Rows[n]["ShopLev"].ToString();
                    }
                    if (dt.Rows[n]["SaleVolume"] != null && dt.Rows[n]["SaleVolume"].ToString() != "")
                    {
                        model.SaleVolume = dt.Rows[n]["SaleVolume"].ToString();
                    }
                    if (dt.Rows[n]["Square"] != null && dt.Rows[n]["Square"].ToString() != "")
                    {
                        model.Square = dt.Rows[n]["Square"].ToString();
                    }
                    if (dt.Rows[n]["ShopPromotor"] != null && dt.Rows[n]["ShopPromotor"].ToString() != "")
                    {
                        model.ShopPromotor = dt.Rows[n]["ShopPromotor"].ToString();
                    }
                    if (dt.Rows[n]["ShopLinkman"] != null && dt.Rows[n]["ShopLinkman"].ToString() != "")
                    {
                        model.ShopLinkman = dt.Rows[n]["ShopLinkman"].ToString();
                    }
                    if (dt.Rows[n]["ShopLinkmanTel"] != null && dt.Rows[n]["ShopLinkmanTel"].ToString() != "")
                    {
                        model.ShopLinkmanTel = dt.Rows[n]["ShopLinkmanTel"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

